<template>
	<view class="content reg-page">
		<view class="input-group">
			

			<view class="input-row border-bottom-1px">
				
				<text class="title">
					<text class="must">*</text>
					<text class="yzb yzb-bitian" />
					性别
				</text>
				<radio-group @change="radioChange" v-model="sex" >
					<label class="radio">
						<radio :value="'男'" :checked="sex == '男'" />
						男
					</label>
					<label class="radio">
						<radio :value="'女'" :checked="sex == '女'" />
						女
					</label>
				</radio-group>
			</view>

			<view class="input-column border-bottom-1px">
				<text class="title">
					<text class="must">*</text>
					<!-- <text class="yzb yzb-bitian" /> -->
					邮箱地址
				</text>
				<view class="input-item" @click="isEdit(editEamil)">
					<m-input type="text" v-model="email" placeholder="请输入邮箱地址" :maxLength="50" ></m-input>
					
				</view>
				
			</view>
			<view class="input-column border-bottom-1px" v-if="!editEmail">
				<text class="title">
					<text class="must">*</text>
					邮箱验证码
				</text>
				<view class="input-item">
					<wInput
						v-model="code"
						type="number"
						placeholder="验证码"
						isShowCode
						codeText="获取验证码"
						ref="runCode"
						@setCode="getVerCode()"
					></wInput>
				</view>
				
			</view>
			
			<view class="input-column border-bottom-1px">
				<text class="title">
					<text class="must">*</text>
					<text class="yzb yzb-bitian" />
					所属学校
				</text>
				<view class="picker">
					<picker @change="bindPickerChange" :value="school" :range="array">
						<input class="padding-10" disabled="true" placeholder="请选择所属学校" :value="school" />
					</picker>
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px">
				<text class="title">
					<text class="must">*</text>
					<!-- <text class="yzb yzb-bitian" /> -->
					入学年份
				</text>
				<view class="input-item" @click="isEdit(editEnrolYear)"><m-input type="text" v-model="userInfo.enrolYear" placeholder="请输入入学年份" :maxLength="50" :disabled="editEnrolYear"></m-input></view>
			</view>
			<view class="input-column border-bottom-1px" >
				<text class="title">
					<text class="must">*</text>
					<!-- <text class="yzb yzb-bitian" /> -->
					专业
				</text>
				<view class="input-item"><m-input type="text" v-model="userInfo.major" placeholder="请输入专业" :maxLength="50"></m-input></view>
			</view>
			<view class="input-column border-bottom-1px">
				<text class="title">
					<text class="must">*</text>
					学生认证
				</text>
				<view class="input-item">
					<m-upimg count="3" url="https://www.cscmkj.cn/starCityAll/user/saveImg" :notli="true" @onUpImg="onUpImg()"></m-upimg>
				</view>
			</view>
			<view class="input-column border-bottom-1px" style="margin-bottom:120upx;text-align: center;">
				<p >
					说明：
				</p>
				<p >
					1.请在本页面提交一张学校的录取通知书/学生证/校园卡学位证/毕业证的正面照片
				</p>
				<p >
					2.照片须保持清晰，但我们不会采集或分析其中的信息，可以自行对学号、序列号、条形码等信息进行遮盖处理。
				</p>
				<p >
					3.后台将进行人工审核，保证信息符合要求。
				</p>
				<p >
					4.对于蓄意伪造、冒用以及欺诈等行为，本方保留封禁乃至报案的权利。
				</p>
				<p >
					5.其他用户无法得知您的实名认证信息。
				</p>
			</view>
			
			
		</view>

		<view class="btn-row"><button type="primary" class="primary" @tap="update">保存</button></view>
	</view>
</template>

<script>
import wInput from '@/components/watch-login/watch-input2.vue'; 
import mInput from '@/components/m-input/m-input.vue';
import config from "@/config/index.config.js";
import mUpimg from '@/components/m-upimg/m-upimg.1.vue'; 
import { warn } from "vue";
export default {
	components: {
		mInput,
		wInput,
		mUpimg
	},
	computed: {
		startDate() {
			return this.getDate('start');
		},
		endDate() {
			return this.getDate('end');
		}
	},

	data() {
		const currentDate = this.getDate({
			format: true
		});
		const start = this.getDate('start');
		return {
			school:'',
			sex:'',
			email:'',
			code:'',
			filePath:'',
			vx:false,
			editSex:false,
			date: currentDate,
			array: ['民政职业技术学院','湖南涉外经济学院'],
			tmpImageUrl: ''
		};
	},
	onLoad() {
	},
	methods: {
		
		onUpImg(pList){
				this.filePath=""
				for(var l in pList){
					this.filePath+=pList[l].path_server+",";
				}
				this.filePath=this.filePath.substring(0,this.filePath.length-1)
			},
		bindPickerChange: function(e) {
			this.school = this.array[e.target.value];
		},

		// bindBirthdayChange: function(e) {
		// 	this.resumeInfo.birthday = e.target.value;
		// },

		// bindDateChange: function(e) {
		// 	this.resumeInfo.timeToWork = e.target.value;
		// },
		//获取验证码
		async getVerCode() {
			if(this.email==null||this.email==""){
				uni.showToast({
					title: '请输入邮箱地址',
					icon: 'none',
					position: 'bottom'
				});
				return false;
			}
			this.$refs.runCode.$emit('runCode');
			let params = {
				email: this.email
			};
			let data = await this.$apis.emailCode(params);
			console.log('getVerCode===', data);
			if (data) {
				uni.showToast({
					title: '获取成功',
					icon: 'none',
					position: 'bottom'
				});
			}
			//终止倒计时（用于突然需要终止倒计时的场景）
			//this.$refs.runCode.$emit('runCode',0);
		},
		radioChange(val) {
			this.sex = val.detail.value;
			console.log('radioChange', val);
		},
		isEdit(editItem){
			if(editItem){
				uni.showToast({
					icon:"none",
					title:"该信息不可二次修改,如需修改，请联系在线客服。"
				})
			}
		},
		// 选择图片
		uploadImgs() {
			let that = this;
			
			uni.chooseImage({
				success(res) {
					let tempFilePaths = res.tempFilePaths;
					that.tmpImageUrl = tempFilePaths[0];
					uni.showLoading({
							title: '图片上传中'
						});
					uni.uploadFile({
					    url:`${config.baseUrl}/starCityAll/user/editHead`,     // 后端api接口
					    filePath: tempFilePaths[0], // uni.chooseImage函数调用后获取的本地文件路劲
					    name:'head',    //后端通过'file'获取上传的文件对象
					    formData: {},
					    header:{
							"Content-Type": "multipart/form-data",
							"Blade-Auth":uni.getStorageSync("token")
						},
					    success:(result) => {
							console.log(result);
					            if(result.data.code==0){
									
									uni.hideLoading();
									this.getUserInfo();
								}
					    }
					});
					
				}
			});
			
		},

		getDate(type) {
			const date = new Date();
			let year = date.getFullYear();
			let month = date.getMonth() + 1;
			let day = date.getDate();

			if (type === 'start') {
				year = year - 60;
			} else if (type === 'end') {
				year = year + 2;
			}
			month = month > 9 ? month : '0' + month;
			day = day > 9 ? day : '0' + day;
			return `${year}-${month}-${day}`;
		},

		// 更新
		async update() {
			// let checkRes = graceChecker.check(this.resumeInfo, formRuleConfig.regResumeBaseRule);
			// if (!checkRes) {
			// 	uni.showToast({
			// 		title: graceChecker.error,
			// 		icon: 'none'
			// 	});
			// 	return;
			// }
			let res = await this.$apis.editUser(this.userInfo);
			if (res) {
				// this.$mRouter.push({
				// 	route: this.$mRoutesConfig.personReume
				// });
				// uni.navigateBack({
				// 	delta: 1
				// });
				uni.showToast({
					icon:"success",
					title:"修改成功"
				})
			}
		}
	}
};
</script>

<style lang="scss">
.yzb-bitian {
	color: $font-color-red;
}
.must{
	color: #ff132a;
}
.input-group {
	border-radius: 10upx;
	margin-top: 10upx;
	overflow: hidden;
	margin-bottom: 120upx;
}

.input-row {
	display: flex;
	flex-direction: row;
	position: relative;
	background: #fff;
	justify-content: space-between;
	align-items: center;
	padding: 15upx 10upx;
}

.input-row .title {
	width: 25%;
	padding: 20upx 0;
	padding-left: 20upx;
	line-height: 50upx;
	font-weight: bold;
	color: $font-color-333;
}

.border-bottom-1px {
	// border-bottom: 1upx solid $border-color-light;
	position: relative;
	&::after {
		position: absolute;
		z-index: 1;
		right: 0;
		bottom: 0;
		left: 20upx;
		height: 1upx;
		content: '';
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		background-color: #e2e2e2;
	}
}

.header {
	display: flex;
	flex-direction: column;
	.tip {
		font-size: $uni-font-size-sm;
		color: $font-color-666;
		margin-left: 20upx;
	}
}

.head-img {
	margin-right: 15upx;
	image {
		width: 160upx;
		height: 160upx;
		border-radius: 50%;
	}
}

radio-group {
	margin-right: 10upx;
}

.radio {
	margin-left: 20upx;
}

.input-column {
	display: flex;
	flex-direction: column;
	background-color: $bgcolor_white;
	padding: 30upx 20upx 10upx 20upx;
	p{
		font-size:26rpx;
	}
	.title {
		margin-left: 10upx;
		color: $font-color-333;
	}

	.input-item {
		// display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.picker {
		margin-left: 10upx;
		position: relative;
		picker {
			font-size: $uni-font-size-lg;
			width: 100%;
		}
	}
	.yzb-next {
		float: right;
		color: $font-color-999;
	}
}

.content {
	background: $bgcolor_white;
}

.btn-row {
	position: fixed;
	bottom: 0upx;
	width: 100%;
	z-index: 99;
	box-sizing: border-box;
	background-color: #fff;
	button {
		background-color: $main-color;
		height: 90upx;
		line-height: 90upx;
		font-size: $font-size-34;
		border-radius: 0;
	}
}
</style>
